libxenlight: remove all cloning logic.
authorKeir Fraser <keir.fraser@citrix.com>
Fri, 8 Jan 2010 11:46:52 +0000 (11:46 +0000)
committerKeir Fraser <keir.fraser@citrix.com>
Fri, 8 Jan 2010 11:46:52 +0000 (11:46 +0000)
replace by simpler xl ctx init/free calls.
also don't segfault if there's no callback for log.

Signed-off-by: Vincent Hanquez <vincent.hanquez@eu.citrix.com>
tools/libxl/libxl_device.c
tools/libxl/libxl_internal.c
tools/libxl/libxl_internal.h

index ddb36ce5090a27e91e131c5931ccddb41fd5216f..7bbc924d180c9c9d7b42f4f2f87bd5443d3e5e89 100644 (file)
@@ -240,9 +240,8 @@ int libxl_devices_destroy(struct libxl_ctx *ctx, uint32_t domid, int force)
     flexarray_t *toremove;
     struct libxl_ctx clone;
 
-    if (libxl_clone_context_xs(ctx, &clone)) {
-        XL_LOG(ctx, XL_LOG_ERROR, "Out of memory when cloning context");
-        return ERROR_NOMEM;
+    if (libxl_ctx_init(&clone, LIBXL_VERSION)) {
+        return -1;
     }
 
     toremove = flexarray_make(16, 1);
@@ -250,7 +249,7 @@ int libxl_devices_destroy(struct libxl_ctx *ctx, uint32_t domid, int force)
     l1 = libxl_xs_directory(&clone, XBT_NULL, path, &num1);
     if (!l1) {
         XL_LOG(&clone, XL_LOG_ERROR, "%s is empty", path);
-        libxl_discard_cloned_context_xs(&clone);
+        libxl_ctx_free(&clone);
         return -1;
     }
     for (i = 0; i < num1; i++) {
@@ -294,7 +293,7 @@ int libxl_devices_destroy(struct libxl_ctx *ctx, uint32_t domid, int force)
         xs_rm(clone.xsh, XBT_NULL, path);
     }
     flexarray_free(toremove);
-    libxl_discard_cloned_context_xs(&clone);
+    libxl_ctx_free(&clone);
     return 0;
 }
 
@@ -304,9 +303,8 @@ int libxl_device_del(struct libxl_ctx *ctx, libxl_device *dev, int wait)
     int rc;
     struct libxl_ctx clone;
 
-    if (libxl_clone_context_xs(ctx, &clone)) {
-        XL_LOG(ctx, XL_LOG_ERROR, "Out of memory when cloning context");
-        return ERROR_NOMEM;
+    if (libxl_ctx_init(&clone, LIBXL_VERSION)) {
+        return -1;
     }
 
     /* Create strings */
@@ -323,7 +321,7 @@ int libxl_device_del(struct libxl_ctx *ctx, libxl_device *dev, int wait)
 
     rc = libxl_device_destroy(&clone, backend_path, !wait);
     if (rc == -1) {
-        libxl_discard_cloned_context_xs(&clone);
+        libxl_ctx_free(&clone);
         return ERROR_FAIL;
     }
 
@@ -335,9 +333,7 @@ int libxl_device_del(struct libxl_ctx *ctx, libxl_device *dev, int wait)
     }
 
     xs_rm(clone.xsh, XBT_NULL, hotplug_path);
-    libxl_free(&clone, hotplug_path);
-    libxl_free(&clone, backend_path);
-    libxl_discard_cloned_context_xs(&clone);
+    libxl_ctx_free(&clone);
     return 0;
 }
 
index eeadbfd71f44bde808df4020d65440f5fc8f7c72..f48e9eb109119ae334ea41f01bd455dca4f76c5d 100644 (file)
@@ -28,28 +28,6 @@ int libxl_error_set(struct libxl_ctx *ctx, int code)
     return 0;
 }
 
-int libxl_clone_context(struct libxl_ctx *from, struct libxl_ctx *to)
-{
-    /* We could just copy the structs, but since
-     * maxsize is not a pointer we need to take care
-     * of our own GC. */
-    *to = *from;
-    to->alloc_ptrs = NULL;
-    to->alloc_maxsize = 256;
-    to->alloc_ptrs = calloc(to->alloc_maxsize, sizeof(void *));
-    if (!to->alloc_ptrs)
-        return ERROR_NOMEM;
-    return 0;
-}
-
-void libxl_discard_cloned_context(struct libxl_ctx *ctx)
-{
-    /* We only need to worry about GC-related fields */
-    (void)libxl_ctx_free(ctx);
-    if (ctx->alloc_ptrs)
-        free(ctx->alloc_ptrs);
-}
-
 int libxl_ptr_add(struct libxl_ctx *ctx, void *ptr)
 {
     int i;
@@ -180,6 +158,9 @@ void xl_logv(struct libxl_ctx *ctx, int loglevel, int errnoval,
     char *s;
     int rc;
 
+    if (!ctx->log_callback)
+        return;
+
     rc = vasprintf(&s, fmt, ap);
     if (rc<0) { s = enomem; goto x; }
 
index 1f7e64af6b4fdd5741c4a658b664838e2bf6b804..44e97d1b0605fe80a8e3ddb1b507c7d2499e5fd1 100644 (file)
@@ -96,23 +96,6 @@ typedef struct {
 int xs_writev(struct xs_handle *xsh, xs_transaction_t t, char *dir, char *kvs[]);
 
 /* memory allocation tracking/helpers */
-int libxl_clone_context(struct libxl_ctx *from, struct libxl_ctx *to);
-static inline int libxl_clone_context_xs(
-                struct libxl_ctx *from, struct libxl_ctx *to)
-{
-    int rc;
-    rc = libxl_clone_context(from, to);
-    if (rc) return rc;
-    to->xsh = xs_daemon_open();
-    return 0;
-}
-void libxl_discard_cloned_context(struct libxl_ctx *ctx);
-static inline void libxl_discard_cloned_context_xs(
-                struct libxl_ctx *ctx)
-{
-    libxl_discard_cloned_context(ctx);
-    xs_daemon_close(ctx->xsh);
-}
 int libxl_ptr_add(struct libxl_ctx *ctx, void *ptr);
 int libxl_free(struct libxl_ctx *ctx, void *ptr);
 int libxl_free_all(struct libxl_ctx *ctx);